﻿using System.Collections.Generic;
using System.Web.Mvc;
using CQIE.OVS.BLL;
using CQIE.OVS.Model;

namespace CQIE.OVS.Web.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            User user = Session["User"] as User;
            ViewBag.User = user.Account;
            return View();
        }
        [HttpGet]
        public ActionResult Login()
        {
            
            return View();
        }

        public void UpdatePwd(string pwd)
        {
            User user = Session["User"] as User;
            user.Password = pwd;
            new UserBLL().Update(user);
        }

        [HttpPost]
        public ActionResult Login(string username,string password)
        {
            IList<QueryConditions> querys = new List<QueryConditions>();
            querys.Add(new QueryConditions("Account","=",username));
            querys.Add(new QueryConditions("Password","=",password));
            UserBLL bll =new UserBLL();
            var list = bll.Find(querys);
            if (list.Count>0 && list[0].root==2)
            {
                Session["User"] = list[0];
                return RedirectToAction("Index");
            }

            ViewBag.error = "1";
            return View();
        }

        public ActionResult Logout()
        {
            Session.Clear();
            return View("Login");
        }

    }
}